#include "Configs.h"
#include "MemTrack.h"

namespace bs
{
	const char* EXPLODE_IMAGE_FILE = "Image";
	const char* EXPLODE_IMAGE_ROW = "Row";
	const char* EXPLODE_IMAGE_COL = "Col";
	
	const char* NPC_MIN_VX = "MinVx";
	const char* NPC_MAX_VX = "MaxVx";
	const char* NPC_VY = "Vy";
	const char* NPC_FIRE_DELAY = "FireDelay";
	const char* NPC_BULLET = "Bullet";
	const char* NPC_BULLET_SND = "BulletSnd";
	const char* NPC_EXPLODE = "Explode";
	const char* NPC_EXPLODE_SND = "ExplodeSnd";
	const char* NPC_NAME = "Name";
	const char* NPC_ID = "Id";
	const char* NPC_IMAGE_FILE = "Image";
	const char* NPC_IMAGE_ROW = "Row";
	const char* NPC_IMAGE_COL = "Col";

	const char* PLAYER_MAX_VX = "MaxVx";
	const char* PLAYER_FRIX = "FriX";
	const char* PLAYER_ACCX = "AccX";
	const char* PLAYER_START_X = "StartX";
	const char* PLAYER_START_Y = "StartY";
	const char* PLAYER_EXPLODE = "Explode";
	const char* PLAYER_EXPLODE_SND = "ExplodeSnd";
	const char* PLAYER_BULLET = "Bullet";
	const char* PLAYER_FIRE_DELAY = "FireDelay";
	const char* PLAYER_IMAGE_FILE = "image";
	const char* PLAYER_IMAGE_ROW = "row";
	const char* PLAYER_IMAGE_COL = "col";

	ExplodeCfg::ExplodeCfg()
		: image(""), row(1), col(1)
	{
	}

	ExplodeCfg::~ExplodeCfg()
	{
	}

	void ExplodeCfg::LoadFromFile(Config& cfg, const char* session)
	{
		this->image = cfg.GetValue(session, EXPLODE_IMAGE_FILE, this->image.c_str());
		this->row = cfg.GetValue(session, EXPLODE_IMAGE_ROW, this->row);
		this->col = cfg.GetValue(session, EXPLODE_IMAGE_COL, this->col);
	}

	NpcCfg::NpcCfg()
		: minVx(50), maxVx(50), vy(10), fireDelay(1500), bullet(""), bulletSnd(""), explode(""), 
		explodeSnd(""), name("npc"), image(""), row(1), col(1) 
	{
	}

	NpcCfg::~NpcCfg()
	{
	}

	void NpcCfg::LoadFromFile(Config& cfg, const char* session, bool isPlane)
	{
		this->minVx = cfg.GetValue(session, NPC_MIN_VX, this->minVx);
		this->explode = cfg.GetValue(session, NPC_EXPLODE, this->explode.c_str());
		this->explodeSnd = cfg.GetValue(session, NPC_EXPLODE_SND, this->explodeSnd.c_str());
		this->name = cfg.GetValue(session, NPC_NAME, this->name.c_str());
		this->image = cfg.GetValue(session, NPC_IMAGE_FILE, this->image.c_str());
		this->row = cfg.GetValue(session, NPC_IMAGE_ROW, this->row);
		this->col = cfg.GetValue(session, NPC_IMAGE_COL, this->col);

		if(isPlane)
		{
			this->maxVx = cfg.GetValue(session, NPC_MAX_VX, this->maxVx);
			this->fireDelay = cfg.GetValue(session, NPC_FIRE_DELAY, this->fireDelay);
			this->bullet = cfg.GetValue(session, NPC_BULLET, this->bullet.c_str());
		}
		else
		{
			this->vy = cfg.GetValue(session, NPC_VY, this->vy);
			this->bulletSnd = cfg.GetValue(session, NPC_BULLET_SND, this->bulletSnd.c_str());
		}
	}

	PlayerCfg::PlayerCfg()
		: maxVx(200.0f), friX(400.0f), x(0), y(0), accX(700.0f), bullet(""),
		explode(""), explodeSnd(""), fireDelay(-1), image(""), row(1), col(1)
	{
	}

	PlayerCfg::~PlayerCfg()
	{
	}

	void PlayerCfg::LoadFromFile( Config& cfg, const char* session )
	{
		this->maxVx = cfg.GetValue(session, PLAYER_MAX_VX, this->maxVx);
		this->friX = cfg.GetValue(session, PLAYER_FRIX, this->friX);
		this->x = cfg.GetValue(session, PLAYER_START_X, this->x);
		this->y = cfg.GetValue(session, PLAYER_START_Y, this->y);
		this->accX = cfg.GetValue(session, PLAYER_ACCX, this->accX);
		this->bullet = cfg.GetValue(session, PLAYER_BULLET, this->bullet.c_str());
		this->explode = cfg.GetValue(session, PLAYER_EXPLODE, this->explode.c_str());
		this->explodeSnd = cfg.GetValue(session, PLAYER_EXPLODE_SND, this->explodeSnd.c_str());
		this->fireDelay = cfg.GetValue(session, PLAYER_FIRE_DELAY, this->fireDelay);
		this->image = cfg.GetValue(session, PLAYER_IMAGE_FILE, this->image.c_str());
		this->row = cfg.GetValue(session, PLAYER_IMAGE_ROW, this->row);
		this->col = cfg.GetValue(session, PLAYER_IMAGE_COL, this->col);
	}
}